from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-28 14:02:16.758261
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 28, Aug, 2022
Time: 14:02:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2355
Nobs: 762.000 HQIC: -50.5722
Log likelihood: 9707.25 FPE: 8.81498e-23
AIC: -50.7830 Det(Omega_mle): 7.83900e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300463 0.054855 5.477 0.000
L1.Burgenland 0.106856 0.036482 2.929 0.003
L1.Kärnten -0.106769 0.019372 -5.511 0.000
L1.Niederösterreich 0.206720 0.076205 2.713 0.007
L1.Oberösterreich 0.113578 0.073899 1.537 0.124
L1.Salzburg 0.252712 0.039019 6.477 0.000
L1.Steiermark 0.035734 0.050889 0.702 0.483
L1.Tirol 0.106897 0.041202 2.594 0.009
L1.Vorarlberg -0.060823 0.035426 -1.717 0.086
L1.Wien 0.049515 0.065723 0.753 0.451
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061009 0.113964 0.535 0.592
L1.Burgenland -0.034892 0.075792 -0.460 0.645
L1.Kärnten 0.047355 0.040246 1.177 0.239
L1.Niederösterreich -0.173760 0.158319 -1.098 0.272
L1.Oberösterreich 0.396743 0.153529 2.584 0.010
L1.Salzburg 0.289752 0.081064 3.574 0.000
L1.Steiermark 0.104942 0.105723 0.993 0.321
L1.Tirol 0.314116 0.085599 3.670 0.000
L1.Vorarlberg 0.026790 0.073599 0.364 0.716
L1.Wien -0.024687 0.136544 -0.181 0.857
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191145 0.028199 6.778 0.000
L1.Burgenland 0.089406 0.018754 4.767 0.000
L1.Kärnten -0.008730 0.009959 -0.877 0.381
L1.Niederösterreich 0.259511 0.039174 6.625 0.000
L1.Oberösterreich 0.134938 0.037989 3.552 0.000
L1.Salzburg 0.045795 0.020058 2.283 0.022
L1.Steiermark 0.017404 0.026160 0.665 0.506
L1.Tirol 0.093700 0.021181 4.424 0.000
L1.Vorarlberg 0.058312 0.018211 3.202 0.001
L1.Wien 0.119620 0.033786 3.540 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107720 0.028645 3.760 0.000
L1.Burgenland 0.047170 0.019051 2.476 0.013
L1.Kärnten -0.014697 0.010116 -1.453 0.146
L1.Niederösterreich 0.192220 0.039794 4.830 0.000
L1.Oberösterreich 0.289882 0.038590 7.512 0.000
L1.Salzburg 0.111837 0.020376 5.489 0.000
L1.Steiermark 0.102267 0.026574 3.848 0.000
L1.Tirol 0.110420 0.021516 5.132 0.000
L1.Vorarlberg 0.069600 0.018499 3.762 0.000
L1.Wien -0.017179 0.034321 -0.501 0.617
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130601 0.052013 2.511 0.012
L1.Burgenland -0.051927 0.034592 -1.501 0.133
L1.Kärnten -0.040270 0.018368 -2.192 0.028
L1.Niederösterreich 0.170302 0.072257 2.357 0.018
L1.Oberösterreich 0.141410 0.070071 2.018 0.044
L1.Salzburg 0.287995 0.036997 7.784 0.000
L1.Steiermark 0.031886 0.048252 0.661 0.509
L1.Tirol 0.161641 0.039067 4.137 0.000
L1.Vorarlberg 0.100807 0.033590 3.001 0.003
L1.Wien 0.069537 0.062318 1.116 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056219 0.041436 1.357 0.175
L1.Burgenland 0.040329 0.027557 1.463 0.143
L1.Kärnten 0.050275 0.014633 3.436 0.001
L1.Niederösterreich 0.220572 0.057563 3.832 0.000
L1.Oberösterreich 0.283636 0.055821 5.081 0.000
L1.Salzburg 0.045816 0.029474 1.554 0.120
L1.Steiermark -0.001113 0.038440 -0.029 0.977
L1.Tirol 0.148144 0.031123 4.760 0.000
L1.Vorarlberg 0.072550 0.026760 2.711 0.007
L1.Wien 0.084387 0.049645 1.700 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180505 0.049620 3.638 0.000
L1.Burgenland -0.005571 0.033000 -0.169 0.866
L1.Kärnten -0.061401 0.017523 -3.504 0.000
L1.Niederösterreich -0.082808 0.068932 -1.201 0.230
L1.Oberösterreich 0.197171 0.066846 2.950 0.003
L1.Salzburg 0.056227 0.035295 1.593 0.111
L1.Steiermark 0.230630 0.046032 5.010 0.000
L1.Tirol 0.493922 0.037270 13.253 0.000
L1.Vorarlberg 0.047562 0.032045 1.484 0.138
L1.Wien -0.054009 0.059451 -0.908 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165964 0.056978 2.913 0.004
L1.Burgenland -0.011056 0.037894 -0.292 0.770
L1.Kärnten 0.067129 0.020122 3.336 0.001
L1.Niederösterreich 0.206299 0.079154 2.606 0.009
L1.Oberösterreich -0.070540 0.076759 -0.919 0.358
L1.Salzburg 0.211349 0.040529 5.215 0.000
L1.Steiermark 0.115787 0.052858 2.191 0.028
L1.Tirol 0.071722 0.042797 1.676 0.094
L1.Vorarlberg 0.121716 0.036797 3.308 0.001
L1.Wien 0.123215 0.068267 1.805 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360242 0.032890 10.953 0.000
L1.Burgenland 0.006160 0.021874 0.282 0.778
L1.Kärnten -0.023322 0.011615 -2.008 0.045
L1.Niederösterreich 0.214237 0.045691 4.689 0.000
L1.Oberösterreich 0.190999 0.044309 4.311 0.000
L1.Salzburg 0.045712 0.023395 1.954 0.051
L1.Steiermark -0.016569 0.030512 -0.543 0.587
L1.Tirol 0.106209 0.024704 4.299 0.000
L1.Vorarlberg 0.073311 0.021241 3.451 0.001
L1.Wien 0.044635 0.039407 1.133 0.257
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040257 0.148639 0.192087 0.157845 0.123947 0.112769 0.066011 0.221753
Kärnten 0.040257 1.000000 -0.004300 0.133173 0.040914 0.095854 0.431001 -0.052339 0.100035
Niederösterreich 0.148639 -0.004300 1.000000 0.337305 0.149549 0.298939 0.107396 0.182936 0.322594
Oberösterreich 0.192087 0.133173 0.337305 1.000000 0.227693 0.331055 0.172685 0.167901 0.265364
Salzburg 0.157845 0.040914 0.149549 0.227693 1.000000 0.147148 0.122466 0.147518 0.131530
Steiermark 0.123947 0.095854 0.298939 0.331055 0.147148 1.000000 0.150855 0.138173 0.079227
Tirol 0.112769 0.431001 0.107396 0.172685 0.122466 0.150855 1.000000 0.115043 0.151983
Vorarlberg 0.066011 -0.052339 0.182936 0.167901 0.147518 0.138173 0.115043 1.000000 0.006833
Wien 0.221753 0.100035 0.322594 0.265364 0.131530 0.079227 0.151983 0.006833 1.000000